import { GameModel } from "../model/GameModel";
import { GlobalModel } from "../model/GlobalModel";
import { LobbyModel } from "../model/LobbyModel";
import { LoginModel } from "../model/LoginModel";
import { UserModel } from "../model/UserModel";


export class ModelMgr {
    global: GlobalModel = new GlobalModel()
    user: UserModel = new UserModel()
    game: GameModel = new GameModel()
    login: LoginModel = new LoginModel()
    lobby: LobbyModel = new LobbyModel()

    initAfterLogin() {
        for (let key in this) {
            if (this.hasOwnProperty(key)) {
                const value = this[key];
                if (value && typeof value === 'object') {
                    const model = this[key] as any;
                    if (model.initAfterLogin) {
                        model.initAfterLogin();
                    }
                }
            }
        }
    }

    clear(model: any) {
        for (let key in this) {
            if (this.hasOwnProperty(key)) {
                const value = this[key];
                if (typeof value === 'number')
                    (this[key] as any) = 0;
                else if (typeof value === 'string')
                    (this[key] as any) = '';
                else if (typeof value === 'boolean')
                    (this[key] as any) = false;
                else if (Array.isArray(value))
                    (this[key] as any) = [];
                else if (value && typeof value === 'object')
                    (this[key] as any) = {};
                else {
                    // 可以根据需要处理其他类型的值
                    (this[key] as any) = null;
                }
            }
        }
    }
}